# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/scorpio_defconfig

pkgname=linux-xiaomi-scorpio
pkgver=3.18.124
pkgrel=0
pkgdesc="Xiaomi Mi Note 2 kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="xiaomi-scorpio"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl gcc6"

# Compiler: GCC 6 (doesn't boot when compiled with newer versions)
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_xiaomi_msm8996"
_commit="8e27b438e8da6c6713b65da75f035438c45b05b9"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
	$_config
	gcc10-extern_YYLOC_global_declaration.patch
	struct-rndis-incomplete-type.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
}

sha512sums="97e9ef9f930923cee2351eeb22bc99c2df438701c17b88c221879fa336f84beb0328b772f0f19b2f39713a8d4f2d22139634f57ca6ade00f5190d7553db58002  linux-xiaomi-scorpio-8e27b438e8da6c6713b65da75f035438c45b05b9.tar.gz
6062ed789e5da3491badbbbadc40b259524f688cea63f09502fa1e57c93a89ac397e29335375ccb80b71f55a0b021f6283a8c5f7b0c09ca64dbea08270c64935  config-xiaomi-scorpio.aarch64
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch
c64c63702c1638987640cf80dc8c36488ad0bc1c4ce6a875b9b98f3de1f1ae1435be7ff7f8b0b164f28ac79a22cf70f3d3fb6c28d8c162b7162ef8ac6f95e02d  struct-rndis-incomplete-type.patch"
